package com.lcs.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.lcs.springcloud.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

@RestController
public class HelloController {

    @Autowired
    private HelloService helloService;
    @GetMapping("/hello")
    @SentinelResource(value="hello", blockHandler = "flowBack", fallback = "err")
    public String hello() throws InterruptedException {
        int a = 10/0;
        return "hello";
    }
    public String flowBack(BlockException e)
    {
        return "你被限流了";
    }
    public String err()
    {
        return "异常了";
    }
    @GetMapping("/flowhello")
    @SentinelResource(value="flowhello", blockHandler = "flowBack")
    public String flowhello() throws InterruptedException {
        String user = helloService.getUser();
        return "线程 hello"+user;
    }
    @GetMapping("/flowhello1")
    @SentinelResource(value="flowhello1", blockHandler = "flowBack")
    public String flowhello1() throws InterruptedException {
        String user = helloService.getUser();
        return "线程 hell1111111111111111111111111o"+user;
    }
}
